/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 15:33:19
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 06:45:53
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/loading.dart';
import 'package:flutter_data_center/controller/camera_controller.dart';

import 'package:get/get.dart';
import 'package:scroll_to_index/scroll_to_index.dart';
import 'camera_group.dart';

class CameraList extends StatelessWidget {
  const CameraList({Key key, this.controller, this.onChange}) : super(key: key);
  final AutoScrollController controller;
  final ValueChanged<int> onChange;

  @override
  Widget build(BuildContext context) => GetBuilder<CameraController>(
        builder: (_controller) => _controller.cameraList.length > 0
            ? ListView(
                scrollDirection: Axis.vertical,
                controller: controller,
                physics: BouncingScrollPhysics(),
                children: List.generate(
                  _controller.cameraList.length,
                  (index) => AutoScrollTag(
                      key: ValueKey(index),
                      controller: controller,
                      index: index,
                      child: CameraGroup(
                          camera: _controller.cameraList[index],
                          index: index + 1)),
                ).toList(),
              )
            : Loading(),
      );
}
